Ubuntu 17.10 uses apt to build a lamp environment, install phpMyAdmin, Redis and extensions, MySQL extensions, turn on error prompts, configure a virtual host

Source: Internet
Author: User
Tags install php php error php redis php script phpmyadmin install redis redis server

Final environment:

Ubuntu17.10, Apache2.4.27, MySQL5.7.20, PHP7.1

1. Installing Apache

Official source has, direct installation:

sudo apt-get install apache2

2. Install MySQL

Official source has, direct installation:

sudo apt-get install Mysql-server

You will be prompted to set the password for MySQL administrator during installation


PS: What software or package is needed, search directly with Apt-cache

sudo apt-cache search < keywords >

After confirming the package name, install it directly with apt-get .

3. Install PHP

Official source has php7.1, direct installation:

sudo apt-get install php7.1 Php7.1-dev

php7.1 is the main program, Php7.1-dev is the 7.1 version of the Toolkit (phpize, Php-config, etc., Phpize can be compiled for PHP to build extension modules, Php-config can get the detailed configuration of PHP).


If you want to install php5.6, recommend this PPA source (even if not installed 5.6, also recommended):ppa:ondrej/php. this source has php5.6 and php7.x and the vast majority of PHP extensions, including Redis, Memcache, MongoDB, and more.

To add a ppa:ondrej/php Source:

sudo add-apt-repository ppa:ondrej/phpsudo apt-get update

Install php5.6:

sudo apt-get install php5.6

4. Restart Apache
Sudo/etc/init.d/apache2 restart

More options:

usage:apache2 {Start|stop|graceful-stop|restart|reload|force-reload}

5. Check Apache

Access http://localhost/. This is the Apache server's default page under/var/www/html, which also describes the Apche related configuration file.

6. Check MySQL

Terminal input MySQL, followed by two Tab, see all about MySQL command package:

[email protected]:~/Downloads/mysql-fae9884$ mysql
mysql                      mysql_install_db
mysqladmin                 mysqloptimize
mysqlanalyze               mysql_plugin
mysqlbinlog                mysqlpump
mysqlcheck                 mysqlrepair
mysql_config_editor        mysqlreport
mysqld                     mysql_secure_installation
mysqld_multi               mysqlshow
mysqld_safe                mysqlslap
mysqldump                  mysql_ssl_rsa_setup
mysqldumpslow              mysql_tzinfo_to_sql
mysql_embedded             mysql_upgrade

Enter mysql-u< your account number >-p, enter the password and go to MySQL:

[email protected]:~/Downloads/mysql-fae9884$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 73
Server version: 5.7.20-0ubuntu0.17.10.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.


7. Check PHP

In case of an accident, the version of PHP should be displayed.

8. Create a PHP probe

sudo vim /var/www/HTML/info. php

Add the following content:

<?phpphpinfo ();

Change owner:

sudo chown www-data:www-data/var/www/html/info.php

Visit http://localhost/info.php to get a detailed page about PHP.

9. Installing phpMyAdmin
sudo apt-get install phpMyAdmin

During installation,

To inquire about the server to be connected, select Apache2;

Ask to create a phpMyAdmin database and select "Yes";

Ask the user and password to set the login phpMyAdmin.

Then the browser accesses: Http://localhost/phpmyadmin

10. Installing Redis Services and Redis extensions

Official source has, direct installation:

sudo apt-get install Redis-server

During this time, some of the required kits will also be installed. After installation, the default self-boot, background run, configuration files in the/etc/redis directory.

The advantage of apt installation is that services and extensions are installed together.

Restart Apche, sudo /etc/init.d/apache2 restart

To access http://localhost/info.php, confirm the Redis extension:

Test it:

Terminal input redis-, followed by a two Tab key, see the commands and tools about Redis:

[email protected]:/etc/redis$ redis-
redis-benchmark  redis-check-rdb  redis-server     
redis-check-aof  redis-cli

REDIS-CLI is a client interface that accesses Redis-server, and executes redis-cli to log on to the Redis server:

For more REDIS-CLI command options, use redis-cli--help to view.

Write another PHP script test, vim/var/www/html/test_redis.php

The contents are as follows:

$redis = new Redis();
$redis->connect(‘‘, 6379);
echo "Connection to server sucessfully";
echo "Server is running: " . $redis->ping(); 

11. Install the MySQL extension

As you can see in the http://localhost/info.php above, there is no MySQL extension. Although MySQL extensions are deprecated in php7, some of the old projects are still needed. Install the MySQL extension.

Here choose Compile Install (php-mysql extension via apt installation, if it is php7.x, it is install pdo_mysql extension)

(1) Search MySQL directly from PECL official station, find the MySQL extension page, click [Browse Source] on the page, select the latest commit, download the tar.gz package. I downloaded the package named mysql-fae9884.tar.gz.

(2) Compile and install:

tar -xf mysql-fae9884.tar.gz
cd mysql-fae9884
./configure --with-php-config=/usr/bin/php-config
sudo make && sudo make install

Front loaded php7.1, also installed Php7.1-dev, here there is phpize and Php-config. --with-php-config is the location of the Php-config Script (command) and can be viewed using Whereis php-config.

After the compilation installation succeeds, there will be a path to the success prompt and the MySQL extension (. so file):

Build complete.
Don‘t forget to run ‘make test‘.

Installing shared extensions:     /usr/lib/php/20160303/  

Then, edit PHP for the Apache configuration file/etc/php/7.1apache2/php.ini, adding a line at the end:


Restart Apche, sudo/etc/init.d/apache2 restart

Visit the http://localhost/info.php and confirm that the MySQL extension is available.

Write a PHP script test: vim/etc/www/html/test_mysql.php

The contents are as follows:

$mysql = mysql_connect(‘‘, ‘root‘, ‘root‘);
if(!$mysql) {
echo ‘Ok‘ . "\r\n";

12. Turn on PHP and Apache error hints

PHP errors are not displayed by default and are turned on below.

(1) Modify the PHP configuration file, under/etc/php/7.1/apache2, open the php.ini.

(2) Search display_errors = Off, modify to On

(3) Search error_reporting = E_all & ~e_notice, modified to E_all | E_strict (not found in the picture search short one point: "error_reporting =").

(4) Modify the Apache configuration file, under/etc/apache2, open apache.conf.

(5) Add two lines at the end of the file:

Php_flag display_errors on
Php_value error_reporting 2039

(6) Restart Apache:

Sudo/etc/init.d/apache2 restart

13. Create a virtual host

Create a virtual host natural with Apache configuration, check out the Apache configuration directory:

/ etc / apache2
├── apache2.conf # The main configuration file, some other configuration files are included through the Include directive
├── conf-available # All available configuration files (the contents of * .conf files are almost commented by default)
├── conf-enabled # Of the available configuration files, which ones are enabled, are usually symbolic links that point to each * .conf file in the conf-available directory above
├── envvars # environment variables
├── magic
├── mods-available # all available modules
├── mods-enabled # which modules are enabled
├── ports.conf # Define port listening
├── sites-available # Here comes the point: all available sites
└── sites-enabled # which sites are enabled

The simple step is to define the site configuration file in the sites-available directory and then establish a symbolic connection to the file in the sites-enabled .

(1) Build configuration

cd /etc/apache2/sites-available/
sudo cp 000-default.conf my.site.conf
vim my.site.conf

Modify the following (note that you do not put the comment and the command line in one line, there will be syntax errors):

<VirtualHost *: 80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request ’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
# Domain name
ServerName my.site
# Domain name alias, you can set multiple, separated by spaces
ServerAlias my.site

ServerAdmin [email protected]
DocumentRoot /var/www/my.site
<Directory "/var/www/my.site /">
# Enable symbolic links
Options FollowSymLinks
DirectoryIndex index.php index.html index.htm
# Note that this configuration will affect the enablement of .htaccess in the local directory
AllowOverride All
Order deny, allow
Allow from All
# Restrict access to directories, multiple directories are separated by spaces
# php_admin_value open_basedir "/var/www/my.site/:/tmp:/usr/lib/php/"
</ Directory>

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl: warn

ErrorLog $ {APACHE_LOG_DIR} /error.log
CustomLog $ {APACHE_LOG_DIR} /access.log combined

# For most configuration files from conf-available /, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available / serve-cgi-bin.conf
</ VirtualHost>

# vim: syntax = apache ts = 4 sw = 4 sts = 4 sr noet

To streamline it is this:

<VirtualHost *:80>
	ServerName my.site
	ServerAlias my.site
	ServerAdmin [email protected]
	DocumentRoot /var/www/my.site
	<Directory "/var/www/my.site/">
	    Options FollowSymLinks
	    DirectoryIndex index.php index.html index.htm
	    AllowOverride All
	    Order deny,allow
	    Allow from All
	    # php_admin_value open_basedir "/var/www/my.site/:/tmp:/usr/lib/php/"
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

(2) Building Symbolic Links

Cd/etc/apache2/sudo ln-s./sites-available/my.site.conf./sites-enabled/my.site.conf

(3) Check grammar

Apachectl Configtest

(4) Add hosts parsing

Vim/etc/hosts, add a line:   My.site

(4) Restart Apache

Sudo/etc/init.d/apache2 restart

Then, follow the configured site Directory/etc/www/my.site to create the directory and test files:

sudo makedir -p /etc/www/my.site
cd /etc/www/my.site/
sudo echo "<h2>Hello, Welcome to my.site!</h2>" > index.html

Browser visits my.site,

OK, done ~~


Reference link:

Configure LAMP environment under Ubuntu Server 16.04
Build LAMP on Ubuntu 16.04
Open PHP and Apache error prompt
Ubuntu 16.04 install redis and php redis extension
Ubuntu Apache virtual host configuration
httpd-vhosts set domain alias
php error prompt open_basedir restriction in effect
Related Links:

PHP and extended PPA source: https://launchpad.net/~ondrej/+archive/ubuntu/php/+index?batch=75&memo=75&start=75
Ubuntu 17.10 use apt to set up a lamp environment, install phpmyadmin, redis and extensions, mysql extension, enable error prompts, configure virtual hosts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.