Deploying PHP Environment and WordPress on Ubuntu 14.04
- 2021-07-16 02:00:21
- OfStack
Software and version selection
Ubuntu 14.04
Ubuntu is a distribution with 1 to 2 users at present, which is maintained by local tyrants behind it, and can be said to be the best choice for lightweight users. 14.04 is the latest version of LTS, which has been released for half a year and is basically the best supported version at present.
Nginx
Nginx is a lightweight, flexible, concurrent Web server.
PHP-FPM
PHP-FPM is the best operation mode officially recommended at present.
MariaDB
A substitute for MySQL, after all, the founder of MySQL has not recommended us to use MySQL.
Basic configuration
Usually when you create an VPS, you will get an IP and an root password, so first log on to your server with ssh:
ssh root@106.186.21.33
# Enter yes to confirm if there is a warning, and then enter your root password
Configure 1 under the public key login, save every login to enter the password, it is highly recommended to upload the public key to a public address like me 1, so as long as one command can be set:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
Then update the package list under 1 and upgrade the existing package:
apt-get update
apt-get upgrade
Modify the host name under 1, and it is best to change it to a domain name that can really access this server:
vi /etc/hostname
vi /etc/hosts
Install the package
apt-get install nginx postfix php5-fpm mariadb-server memcached
apt-get install php-pear php5-mysql php5-curl php5-gd php5-mcrypt php5-memcache
apt-get install python make screen git wget zip unzip iftop vim curl htop iptraf nethogs
nginx: Web Server
postfix: SMTP Server to support sending mail locally
php5-fpm: PHP Process Manager, and PHP Interpreter
mariadb-server: Class MySQL Database
memcached: Memory-based caching, which is used by many programs
php-pear: PHP Package manager of
php5-mysql: PHP MySQL Database driven
php5-curl: 1 A HTTP Protocol library
php5-gd: 1 Image processing library
php5-mcrypt: 1 Encryption algorithm library
php5-memcache: Memcached Drive
python: 1 Commonly used scripting language interpreters
make: 1 Commonly used build tools
screen: 1 Commonly used Shell Session management tool
git: 1 Common version control tools
wget, curl: Commonly used file download tools
zip, unzip: ZIP Compression and decompression tools
iftop, iptraf, nethogs: Commonly used traffic monitoring tools
vim: 1 Commonly used editors
htop: 1 Commonly used process monitoring tools
Installing WordPress
Create a new normal user and switch to this user
adduser wordpress
su wordpress
cd ~
To download WordPress, please go to official website to check the download address of the latest version:
wget http://cn.wordpress.org/wordpress-3.9-zh_CN.zip
Unzip file:
unzip wordpress-*.zip
Set file permissions:
chmod -R 750 wordpress
Remove the installation package:
rm wordpress-*.zip
Back to root:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
0
Configuring PHP-FPM
Create 1 process pool for WordPress:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
1
This is a very typical configuration file, through listening Unix Socket to provide services, dynamically adjust the number of processes, up to 10 processes, minimum 3 processes:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
2
Configuring Nginx
Delete the default site for Nginx:
rm /etc/nginx/sites-enabled/default
Create 1 new site:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
4
This configuration file has rewritten the request to index. php, and you can use the "fixed link" function directly in WordPress:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
5
If you want to jump all other domain names to your site, you can add this paragraph:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
6
Then we need to fix one Bug for Nginx and PHP-FPM:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
7
Change the line beginning fastcgi_param SCRIPT_FILENAME to read:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Add permission to read WordPress files for Nginx:
mkdir ~/.ssh; curl 'https://raw.githubusercontent.com/jysperm/meta/master/Key/JyAir.pub' >> ~/.ssh/authorized_keys; chmod -R 700 ~/.ssh;
9
Configuring MySQL
Enter the MySQL console:
mysql -p
# Need to enter your MySQL root password
# Create a database
CREATE DATABASE `wordpress`;
# Create a new user for WordPress
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';
# Grant permissions
apt-get update
apt-get upgrade
3
# Exit
QUIT
Restart
Ok, the configuration has been completed, so we can restart the server directly, so that all services will restart and use the new configuration:
reboot