Detailed tutorial on installing PHP and Nginx on Centos7

Detailed tutorial on installing PHP and Nginx on Centos7

As the application of centos on the server side becomes more and more popular, centos7 is also being used more and more. In the past two years, I have gone from a novice who rarely touches the maintenance of centos server to more and more basic maintenance operations. While it has brought me a lot of troubles, it has also increased my knowledge of setting up and operating centos servers. Today I will record it step by step.

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 background. I think the reasons are:

1. The cost of PHP is low

2. Quick introduction to PHP

3. The development cycle of PHP is relatively short

4. The birth of tp5 improves the efficiency of PHP interface development. Because of so many demands, the server configuration of many companies needs to be able to support the PHP environment in order to complete the project construction. In fact, there are generally two types of software installation on centos. 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 to the corresponding php source and complete the step-by-step installation process through yum install. Here I will only talk about how to compile and install and the compilation and installation process.

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

yum remove php*

Step 2: 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

Step 3. Go to the PHP official website http://php.net/downloads.php to view the tar.gz link to be downloaded, as shown in the figure below:

List of php versions

On this page, select the file source for the country you want to download

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

Enter the operation directory: cd /usr/local

Download the file: wget http://tz1.php.net/distributions/php-7.2.10.tar.gz

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

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

Then compile it 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 with the following command:

make && make install

If there are errors or dependencies during the installation process, you need to solve them 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 then delete it, or you can ignore it. After that, we modify the environment variables to point to the file directory we installed. The operation is as follows:

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

Add export PATH="/usr/local/php/bin:$PATH" to the end of the file

Where "/usr/local/php/bin" is the specific path for your installation. After saving and exiting, execute 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 Nginx is also a basic configuration. The compilation and installation methods are similar:

The first step is to check and install related dependency packages

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

yum -y install zlib zlib-devel openssl 

yum -yinstallopenssl-devel pcre pcre-devel

Step 2. Go to the nginx official website to find the version link you want to install. The official website address is: http://nginx.org/download/, as shown in the figure below:

Nginx version list

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

Enter the directory: cd /usr/local

Download the file: wget http://nginx.org/download/nginx-1.8.0.tar.gz

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

Enter the unzipped file directory: cd nginx-1.8.0

Then compile and install through the command:

./configure 
make && make install

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

After starting, verify whether the service is really started. Use a browser to access the server address to see if it is successfully started. I personally like to verify it through curl http://localhost, because if some server providers prohibit port 80 or the site, it cannot be accessed through an external browser. Of course, you can also use grep or nstat to check whether the corresponding service has been started.

At this point, the installation of PHP and nginx under centos7 is over. If you have more centos server configuration exchanges, you can leave a comment at the end of the article.

Summarize

The above is a detailed tutorial on how to install PHP and Nginx on Centos7. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to install PHP7.4 and Nginx on Centos
  • Detailed tutorial for installing nginx on centos8 (picture and text)
  • Solve the problem of "Welcome to nginx on Fedora!" after installing nginx on Centos7, and there is no default.conf file in the conf.d directory
  • How to install Nginx in CentOS7 and configure automatic startup
  • Detailed explanation of Centos7 source code compilation and installation of Nginx1.13
  • Detailed process of installing nginx1.9.1 on centos8

<<:  Three ways to share component logic in React

>>:  A brief talk about MySQL semi-synchronous replication

Recommend

Detailed explanation of the use of MySQL mysqldump

1. Introduction to mysqldump mysqldump is a logic...

MySQL horizontal and vertical table conversion operation implementation method

This article uses examples to illustrate how to i...

Solving problems encountered when importing and exporting Mysql

background Since I converted all my tasks to Dock...

Complete steps for Nginx to configure anti-hotlinking

need: Usually, sites want to prevent videos and p...

Vue implements login jump

This article example shares the specific code of ...

Vue close browser logout implementation example

Table of contents 1. beforeunload event 2. Unload...

Vue folding display multi-line text component implementation code

Folding display multi-line text component Fold an...

HTML page native VIDEO tag hides the download button function

When writing a web project, I encountered an intr...

How to update the view synchronously after data changes in Vue

Preface Not long ago, I saw an interesting proble...

Introduction to JavaScript Number and Math Objects

Table of contents 1. Number in JavaScript 2. Math...

Continuous delivery using Jenkins and Docker under Docker

1. What is Continuous Delivery The software produ...

Implementation of CSS loading effect Pac-Man

emmm the name is just a random guess 2333 Preface...