Note: This article configures the Nginx server to run PHP
1. Open the CLI of Ubutun and update the source
apt update
Copy the code
2. Install nginx
apt install nginx
Copy the code
Create a soft connection and map the nginx configuration to the /var/www directory
ln -s /etc/nginx /var/www
Copy the code
4. Install PHP. Ubuntu18 installs php7.2 by default
apt install php
Copy the code
5. Create a soft connection and map the PHP configuration to the /var/www directory
ln -s /etc/php /var/www
Copy the code
6. Install PHP extension FPM
apt install php7.2-fpm
Copy the code
7. Find the nginx configuration file (/var/www/nginx/sites-enabled/default) and replace it with the following code
server {
listen 80;
server_name _;
root /var/www/html;
index index.html index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
includefastcgi_params; }}Copy the code
8. Restart the nginx server
/etc/init.d/nginx restart
Copy the code
9. Create an index. PHP file in the root directory of the website (/var/www/html) and fill it with the following code
echo phpinfo(); ? >
Copy the code
If the following configuration page is displayed, it indicates that the Nginx and PHP environment are configured successfully.
11. Next, install mysql
apt install mysql-server
Copy the code
Create a soft connection and map the mysql configuration to the /var/www directory
ln -s /etc/mysql /var/www
Copy the code
13. Install the PHP-mysql extension driver
apt install php7.2-mysql
Copy the code
14. Open the mysql configuration file (/ var/WWW/mysql/mysql. Conf., d/mysqld. CNF), [mysqld] in the next row to add the following configuration to set up the mysql character set
character-set-server=utf8
Copy the code
15. Restart mysql for the configuration to take effect
/etc/init.d/mysql restart
Copy the code