Home  >  Article  >  Database  >  Detailed introduction to building Apache+PHP+MySQL environment on Alibaba Cloud CentOS7

Detailed introduction to building Apache+PHP+MySQL environment on Alibaba Cloud CentOS7

黄舟
黄舟Original
2017-03-24 13:17:471755browse

I recently wanted to build an Alibaba Cloud LMAP environment, and I chose CentOS7 to build it. Through this article, I will share with you how to build an Apache+PHP+MySQL environment using Alibaba Cloud CentOS7. Friends who are interested should take a look together

I recently wanted to build an LMAP environment for Alibaba Cloud and chose CentOS7. Do the building.

1.Apache

Centos7 has the httpd service installed by default, but it has not been started.

If you need a new installation, you can yum install -y httpd

Start the service: systemctl start httpd.service

Set automatic startup at boot: systemctl enable httpd.service

ApacheConfiguration file:/etc/httpd/conf/httpd.conf

The default storage directory of the project is /var/www/html

You can use vi to edit or use SFTP to download and edit.

Check and open port 22 of the server: iptables -I INPUT -p tcp --dport 22 -j ACCEPT

vi /etc/httpd/conf/httpd.conf #编辑文件
ServerSignature On #添加,在错误页中显示Apache的版本,Off为不显示
Options Indexes FollowSymLinks #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)
#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)
AllowOverride None  #修改为:AllowOverride All (允许.htaccess)
AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)
#Options Indexes FollowSymLinks #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)
DirectoryIndex index.html #修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php(设置默认首页文件,增加index.php)
MaxKeepAliveRequests 500 #添加MaxKeepAliveRequests 500 (增加同时连接数)
:wq! #保存退出
systemctl restart httpd.service #重启apache
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除默认测试页

2. Installation PHP5

##Install PHP main program:

yum -y install php

Install PHP components to enable PHP to support MariaDB

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp 
php-soap curl curl-devel

Restart: systemctl restart httpd.service

3. Install mysql

The yum source of CentOS7 does not have mysql by default. In order to solve this problem, we must first download the repo source of mysql.

1. Download the mysql repo source

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. Install the mysql-community-release-el7-5.noarch.rpm package

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

After installing this package, you will get two mysql yum repo sources: /etc/yum.repos.d/mysql-community.repo, /etc/yum.repos.d/mysql-community-source .repo.

3. Install mysql

$ sudo yum install mysql-server

Just follow the steps to install it. However, after the installation is completed, there is no password and you need to reset the password.

4. Reset password

Before resetting the password, you must first log in

$ mysql -u root

When logging in, you may get the following error: ERROR 2002 ( HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2). The reason is the access permission issue of /var/lib/mysql. The following command changes the owner of /var/lib/mysql to the current user:

$ sudo chown -R root:root /var/lib/mysql

Then, restart the service:

$ service mysqld restart

Next log in to reset password:

$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > exit;

5. Open port 3306

$ sudo vim /etc/sysconfig/iptables

Add the following content:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

Save and restart the firewall :

$ sudo service iptables restart

In this way, other clients can also connect to the mysql service.

mysql data directory/var/lib/mysql

Appendix:

linux Under phpMyAdmin, "mysqli extension is missing, please check the PHP configuration."

Cause: the mysqli extension is not installed, or you did not add extension=mysqli.d to php.ini

##Solution: yum install php-mysql Then restart apache

Package project tar -zcvf /home/files.tar.gz /files Packaging

Unzip tar -xzvf files.tar.gz

The above is the detailed content of Detailed introduction to building Apache+PHP+MySQL environment on Alibaba Cloud CentOS7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn