Home > Article > Backend Development > How to install the php environment on Alibaba Cloud CentOS
How to install the PHP environment in Alibaba Cloud: first install the software packages that PHP relies on when compiling; then use the domestic Sohu mirror station to download the PHP installation package; then configure PHP; and finally execute the "make install" command to install it. Can.
#In this article, nginx and mysql have been installed before introducing the installation of the php environment.
Recommended: "PHP Tutorial"
1. Installation
Use the domestic Sohu mirror station to download php5.6 and install it Package, execute:
wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz
Before installation, first install the software packages that php5.6 depends on when compiling. As follows:
yum -y install gcc gcc-c++ libxml2 libxml2-devel
Next, unzip and install php5.6, first perform the decompression:
tar -xf php-5.6.2.tar.gz
Then enter the decompression directory of php5.6, now start configuring php5.6, use the following command:
cd php-5.6.2
The function of --enable-fpm in the above command is to enable the fastcgi function of php, that is, to enable the php-fpm function, –with -mysql=/usr/local/mysql is to enable PHP to support mysql. /usr/local/mysql is the installation path of the mysql database. Note that if the following error is reported here:
Error configure: error: Cannot find MySQL header files under /usr/local/mysql, you can try the following solution:
--with-mysql=/usr/local/mysql,
Change it to
--with-mysql或--with-mysql=/usr
–enable-mbstring means to enable the mbstring module. The main function of the mbstring module is to detect and conversion encoding, providing corresponding string functions for multi-byte operations. Currently, the internal encoding of PHP only supports ISO-8859-*, EUC-JP, and UTF-8. Other encoding languages cannot be displayed correctly on the PHP program, so we need to enable the mbstring module.
After this step is successful, you will see the following interface:
Next, compile and install. First execute the make command. After success, you will see the following interface. :
Just execute the make install command again. At this time, you can use php -v to view the version information after successful installation.
2. Configuration
After the installation is successful, do the basic configuration operations. After the above installation, there is no php in the /usr/local/lib directory .ini file. First copy the template provided by the php installation file, as follows:
cp php.ini-production /usr/local/lib/php.ini
At this time, nginx in the server environment still does not support it. For PHP, requests related to PHP must be processed through fastcgi. PHP needs the php-fpm component to support it. This is the command used when configuring PHP - enable-fpm.
After the php-fpm function is enabled, php-fpm also needs to be configured. In fact, the php-fpm configuration file has already provided us with a configuration file template when installing php. The template is /usr/local/etc/php-fpm.conf.default. Make a copy of this file and rename it to php-fpm.conf, as follows:
cp /usr/local/etc/ php-fpm.conf.default /usr/local/etc/php-fpm.conf
In order to start php-fpm as a service. We need to copy the /sapi/fpm/init.d.php-fpm file in the PHP installation directory. As follows:
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
At this time, the php-fpm file does not have execution permission. Grant execution permissions to php-fpm, start php-fpm, and execute the following command:
chmod a x /etc/init.d/php-fpm
/etc/init.d/php- fpm start
Check after starting:
Port 9000 is the default listening port of php-fpm.
# Next to configure nginx to support it to support PHP, as follows:
Location ~ \ .php $ {
Root html ## fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Then create a new file index.php (/usr/local/nginx/html/index.php) in the root directory of nginx website with the following content:
e2d0e752df2c971bca1fcef6e50119b4
Go to the /usr/local/nginx/sbin/ directory, execute ./nginx to start nginx, and then enter the server ip/index.php in the browser , if you see the following information, it proves that the installation has been started successfully:
The above is the detailed content of How to install the php environment on Alibaba Cloud CentOS. For more information, please follow other related articles on the PHP Chinese website!