Home  >  Article  >  Operation and Maintenance  >  How to install PHP and Nginx on Centos7

How to install PHP and Nginx on Centos7

PHPz
PHPzforward
2023-05-14 15:37:061828browse

1. Install PHP

As WeChat became popular in 2013, the use of PHP has become popular again. Many companies on the market choose to use PHP as their application backend. Personally I think the reasons are

1. The cost of PHP is low

2. It’s quick to get started with PHP

3. The development cycle of PHP is relatively short

4. The birth of tp5 has improved the efficiency of PHP interface development. Because there are so many demands, many companies' server configurations need to be able to support the PHP environment to complete project construction. In fact, there are generally two types of centos installation software. The first is quick installation and the second is compilation and installation. I personally recommend compilation and installation. As for the quick installation method, it is simple and fast. Just load it into the corresponding php source and complete it through yum install. For the step-by-step installation process, I will only talk about how to compile and install and the process of compiling and installing.

The first step is to check whether the system has php by default before installation. You can check it by searching for php files or processes. If it is installed and it is not the version we need, you can uninstall the relevant files through the following command. :

yum remove php*

The second step is to install related php dependencies

yum install -y gcc gcc-c libxml2- devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel freetype freetype-devel

The third step is to go to the PHP official website to view the tar.gz link to be downloaded, as shown below Shown:

How to install PHP and Nginx on Centos7

php version list

How to install PHP and Nginx on Centos7

Select the file source of the country you want to download on this page

After selecting the file source, copy the file download link, and download, compile and install it through the wget command in the system. Personally, I am accustomed to operating in the /usr/local directory. The specific steps are as follows:

Enter the operating directory: cd /usr/local

Download the file: wget

Extract the file: tar -zxvf php-7.2.10.tar.gz

Enter the decompressed file directory: cd php -7.2.10.tar.gz

Then compile with the following command:

./configure --prefix=/usr/local/php --with-config-file- path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-zlib -- with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc - -enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts -with-mcrypt=/usr/include --with-mysql=shared,mysqlnd --with- mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-ftp --enable-session --with-gettext --with-jpeg-dir --with-freetype-dir --enable-fastcgi --without-gdbm --disable-fileinfo

Then complete the final compilation and installation through the following command:

make && make install

If the installation process prompts that there are errors or dependencies, it needs to be solved according to the specific situation. At this point, we can use the php -v command to check whether the installation is successful.

Note: If the version you are viewing is inconsistent with the version you installed, you can find the location of the prompted version file and delete it, or you can leave it alone. After that, we point to the file directory we installed by modifying the environment variable. The operation method is as follows:

First edit the environment variable file: vim /etc/profile

Add export path= at the end of the file "/usr/local/php/bin:$path"

where "/usr/local/php/bin" is the specific path of your installation. After saving and exiting, just make the following changes and execute the command:

source /etc/profile

At this time, we use php -v again to view the current version and we can see the version number we installed.

2. Install nginx

nginx is the most mainstream server software besides apache, so installing ngix is ​​also a basic configuration. The compilation and installation methods are similar. :

The first step is to check and install the relevant dependency packages

yum -y install gcc gcc-c++ autoconf automake make

yum -y install zlib zlib-devel openssl 

yum -yinstallopenssl-devel pcre pcre-devel

The second step is to go to the nginx official website and find the link to the version you want to install. The official website address is: as shown in the figure below:

How to install PHP and Nginx on Centos7

nginx version list

Copy the corresponding version link, enter the above operation directory, /usr/local to operate

Enter the directory: cd /usr/local

Download the file: wget

Decompress the file: tar -zxvf nginx-1.8.0.tar.gz

Enter after decompression File directory: cd nginx-1.8.0

Then compile and install through the command:

. /configure 
make && make install

After the installation is completed, there will be an additional nginx folder under the /usr/local folder, which contains conf, html, logs, and sbin files. We only need to run ./sbin/nginx to start the nginx service.

After startup, verify whether the service is really started. Visit the server address with a browser to check whether it is started successfully. I personally like to verify it through the curl method, because if some server providers prohibit 80 or site port, through the browser of the external network It cannot be accessed. Of course, you can also check whether the corresponding service has been started through grep or nstat.

The above is the detailed content of How to install PHP and Nginx on Centos7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete