Do you want to lớn get a cheap and easy-to-use VPS (Virtual Private Server)? Then, Vultr, Linode or Digital Ocean will be a good option for you. Vultr provides users with a One-Click WordPress app. However, it includes PHP 5.6. If you want PHP 7.0 or 7.1, you will need lớn upgrade the PHP version manually.
Bạn đang xem: How to install php 7
You need some knowledge in Linux to lớn run websites on Amazon AWS, DigitalOcean or Vultr. You may experience extreme ức chế due to server issues when using AWS or Vultr. Cloudways makes it easier khổng lồ run WordPress websites with AWS, DigitalOcean, Linode or Vultr servers.
I prefer lớn installing WordPress on Ubuntu from scratch rather than using the One-Click WordPress app. You can create Snapshots with Vultr, which make thing easy. You can destroy current server and create a new hệ thống using a snapshot.
You can easily install PHP 7.0 or 7.1 and WordPress by following the steps described below.
Deploy a new server
If you bởi vì not have a Vultr account, you can create one at Vultr.com.
Choose a server Location
First, select a vps Location. You can choose one from 15 locations.
If you want to lớn use the cheapest plan (USD2.5/month), please select "New York (NJ)." If you choose other location than "New York (NJ)," the $2.50/mo plan will be disabled, saying "Temporarily Sold Out."
Choose a server Type
Next, you need lớn choose a server Type.
If you want, you can choose a vps Type from snapshots. I chose "Ubuntu 16.10 x64" as a test. However, you should choose "Ubuntu 16.04 LTS" instead of "16.10" to receive Long Term Support.
Choose a vps Size
Now, choose a hệ thống Size.
You can choose a plan from $2.5/mo. If this plan is not available, please kiểm tra the server Location. You might need khổng lồ choose "New York (NJ)" lớn select the cheapest plan.
Now you can deploy a server. You can create SSH Keys which will help you khổng lồ manage your server with ease.
Install WordPress on a LEMP Configuration
You need to log into SSH to perform the steps below. On Windows, please use putty.exe to log into SSH, which makes things easy. You can download it from https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html.
You can also use the console lớn log into your server. The root password for your hệ thống can be found under the detailed page of your sever.
Update existing packages
apt-get update && apt-get upgradeAlso it"s important khổng lồ update your hệ thống regularly for security.
Install and configure PHP 7.0
Since Ubuntu 16.04, PHP 7.0 has replaced PHP 5.x & become the mặc định version of PHP in the official Ubuntu application repository. You can install và configure PHP 7.0 on your Ubuntu 16.04 or Ubuntu 16.10 system as follows. First of all, you can danh sách all of the available PHP 7.0-related packages for review:
apt-cache pkgnames | grep php7.0Then you can install the package your to-be-deployed application requires.
If you want to lớn deploy your application based on the LEMP stack, you can install the following packages after installing Nginx:
sudo apt-get install -y nginxsudo apt-get install -y php7.0 php7.0-fpm php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zipYou can choose to install Apache instead of Nginx. (However, in the section "Installing the WordPress files" below, I will describe how lớn install WordPress in the environment where Nginx is installed.)
sudo apt-get install -y apache2sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zipWhen the installation is complete, you can check the php version installed on your server:
php -vThe đầu ra will be like the following:
sudo nano /etc/php/7.0/fpm/php.iniI modified the following php settings:
I also changed ";cgi.fix_pathinfo=1" to "cgi.fix_pathinfo=0". (I am not sure whether it"s needed or not. I just followed Vultr documentation on installing PHP 5.5.)
For security, I made changes as follows:Changed file_uploads = On lớn file_uploads = Off (To upload images properly, this option should be set lớn On)Changed sql.safe_mode=Off to sql.safe_mode=OnSet allow_url_fopen khổng lồ OffAdded "register_globals = Off" at the over of the php.ini file
Remember khổng lồ restart Apache or Nginx if you make any changes khổng lồ that file or any other PHP config files:
sudo systemctl restart apache2.serviceor:
sudo systemctl restart nginx.service php7.0-fpm.service
Install và configure PHP 7.1If you want to lớn install PHP 7.1 instead of PHP 7.0, a convenient method is to use the PPA (Personal Package Archives) repository.
First of all, you need to add specified PPA to lớn the system apt repository:
sudo apt-get install -y python-software-propertiessudo add-apt-repository -y ppa:ondrej/phpsudo apt-get update -y(Actually, python-software-properties was already installed, you can ignore it.)
Then you can danh sách all of the available PHP 7.1-related packages for review:
apt-cache pkgnames | grep php7.1From now on, you can install và configure PHP 7.1 in the same fashion as mentioned in the section about PHP 7.0 above. Basically, replacing 7.0 with 7.1 in relevant commands will get your job done.
To store and manage databases, you need lớn install MySQL. You can easily install it by typing the following command in the console:
sudo apt-get install mysql-serverDuring the installation process, you will be asked lớn set a root password for MySQL. Once you have set the root password, you will have to lớn tell MySQL khổng lồ generate the directory structure where it will store databases.
sudo mysql_install_dbLet"s finish it up by running a security script that will modify some default insecurities.
sudo mysql_secure_installationJust type the MySQL root password & type n if you don’t want to change it. After that, type y lớn every question.
You can check the MySQL version installed on your hệ thống by entering the following command:
mysql -VThe output đầu ra will be lượt thích the following:
mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using EditLine wrapper
Set Timezone (optional)By default, the timezone of your server is UTC (also known as Greenwich Mean Time) but this can be changed. It may be better lớn use the same timezone which a majority of your users are located in, or that you live in lớn make log tệp tin timestamps more sensible.
sudo dpkg-reconfigure tzdataThe following popup will appear for you to lớn set your timezone:
At this point, your LEMP vps is up and running.
Configuring Nginx to lớn serve WordPress
Now start your WordPress installation by creating an Nginx hệ thống block for your site.
sudo nano /etc/nginx/sites-available/wordpressPlease copy the code below và then pasted it into the newly created tệp tin (/etc/nginx/sites-available/wordpress) in the text editor:
server gzYou can change the root directory as you wish. In this case, the root directory is "/var/www/wordpress."
Please modify "server_name domain.com;" to reflect your actual domain name name, such as:
server_name exmple.com www.example.com;This is a well tuned WordPress configuration file with permalinks support. Save (Ctrl+O) và close the file (Ctrl+X). Let"s enable the hệ thống block by symlinking:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpressNext, delete the Nginx default server block:
sudo rm /etc/nginx/sites-enabled/defaultNow, let"s tune the main Nginx configuration file:
sudo nano /etc/nginx/nginx.confMake sure that the number of worker processes is equal khổng lồ the number of cores in your instance.
user www-data;worker_processes 1;pid /run/nginx.pid;Add use epoll; to the events block.
events worker_connections 1024;multi_accept on;use epoll;I also changed "worker_connections" (whose mặc định value is 768) to lớn 1024 by referring to lớn a Digital Ocean document.
Add client_max_body_size & server_tokens off directive. Please set keepalive_timeout to lớn 30 seconds.
### Basic Settings##sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 30;types_hash_max_size 2048;server_tokens off;client_max_body_size 100m;# server_names_hash_bucket_size 64;# server_name_in_redirect off;include /etc/nginx/mime.types;default_type application/octet-stream;Make sure that the whole Gzip settings block looks lượt thích this:
sudo service nginx restart
Setting up the MySQL databaseIn this step, you"ll create the database user & tables. Connect khổng lồ SSH và log into the MySQL shell:
mysql -u root -pYou need to enter your MySQL root password. You will need to lớn create a WordPress database, along with a user in the database. First, let"s make the database (feel không lấy phí to give it whatever name you like):
CREATE DATABASE yourdb;CREATE USER "dbuser"
"localhost";FLUSH PRIVILEGES;where "yourdb" is the database you want to create, "dbuser" is a user in the database, & "yourpassword" is the password for the user.
Exit the MySQL shell:
Installing the WordPress filesNow it"s almost there! Let"s proceed khổng lồ installing WordPress.
First create & navigate lớn the site root directory:
mkdir /var/www/cd /var/www/Now, download the latest version of WordPress:
wget http://wordpress.org/latest.tar.gzExtract it from the archive using the following command:
tar -xzvf latest.tar.gzGive the permissions of /var/www/wordpress to www-data user. It will allow future automatic updating of WordPress plugins and file editing with SFTP.
sudo chown -R www-data:www-data wordpress/sudo usermod -a -G www-data www-dataFinally, everything is done.
If you connect khổng lồ your domain name name or your hệ thống IP address, the famous WordPress installation screen will appear. If an error message (such as, "404 not found nginx"), you can kiểm tra error logs:
sudo tail -n trăng tròn /var/log/nginx/error.logIt"s possible to lớn migrate your existing WordPress site using normal methods such as using the Duplicator plugin or manually. You can consider installing phpMyAdmin to lớn manage your database. Just upload the phpMyAdmin files/folders lớn your vps using sFTP. (You might need khổng lồ take some measures to lớn prevent unauthorized access khổng lồ phpMyAdmin.)
There are many documents about installing WordPress on Ubuntu. However, it"s not easy khổng lồ follow such documents for beginners. I referred lớn documents from Vultr & Digital Ocean.
If you have problems installing or managing your server in an unmanaged VPS (such as Vultr, Digital Ocean or Linode), it will be better to use managed VPS or a shared hosting such as Siteground. Personally, I have used Bluehost, iPage, GoDaddy & Siteground. Among them, I felt Siteground"s shared hosting is stable & good in performance. This blog is currently hosted with Bluehost VPS. Bluehost VPS is also stable và offers good persomance. However, naturally it"s relatively expensive than shared hosting plans. I consider changing it lớn Siteground when the hosting period is expired.
Just for your reference: You can get a không lấy phí one lớn two month DigitalOcean trial by singing up through the following referral liên kết which gives you $10 credit for free: