Ubuntu 17.10 uses apt to build a lamp environment, install phpmyadmin, redis and extensions, mysql extensions, enable error messages, and configure virtual hosts,
Final environment:
Ubuntu17.10, Apache2.4.27, MySQL5.7.20, and PHP7.1
1. install apache
Official sources: Install directly:
sudo apt-get install apache2
2. Install mysql
Official sources: Install directly:
sudo apt-get install mysql-server
During installation, you will be prompted to set the MySQL administrator password.
========================================================== ================================
PS: Use apt-cache to search for software or packages.
Sudo apt-cache search <keyword>
After confirming the package name, use apt-get install to install the package.
3. install php
Official sources include php7.1, which can be directly installed:
sudo apt-get install php7.1 php7.1-dev
Php7.1 is the main program, and php7.1-dev is the toolkit of version 7.1 (including phpize and php-config). phpize can create extension modules for compiled php, php-config can obtain detailed php configuration ).
========================================================== ================================
If php5.6 is to be installed, we recommend this PPA source (even if 5.6 is not installed ):Ppa: ondrej/php.This source includes php5.6, php7.x, and most php extensions, including redis, memcache, and mongodb.
AddPpa: 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 overview page of the apache server under/var/www/html. It also introduces the related configuration files of apche.
6. Check mysql
Enter mysql on the terminal and press two tabs to view all command packages related to mysql:
mingc@mingc-GE60-2PL:~/Downloads/mysql-fae9884$ mysqlmysql mysql_install_dbmysqladmin mysqloptimizemysqlanalyze mysql_pluginmysqlbinlog mysqlpumpmysqlcheck mysqlrepairmysql_config_editor mysqlreportmysqld mysql_secure_installationmysqld_multi mysqlshowmysqld_safe mysqlslapmysqldump mysql_ssl_rsa_setupmysqldumpslow mysql_tzinfo_to_sqlmysql_embedded mysql_upgrademysqlimport
Enter mysql-u <your account>-p, press enter, enter the password, and enter mysql:
mingc@mingc-GE60-2PL:~/Downloads/mysql-fae9884$ mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 73Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
7. Check php
php -v
The php version should not be displayed unexpectedly.
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 obtain the PHP details page.
9. Install phpmyadmin
sudo apt-get install phpmyadmin
During installation,
Ask the server you want to connect to and select apache2;
Ask to create the phpmyadmin database and select "yes ";
Ask you to set the user and password for logging on to phpmyadmin.
Then the browser accesses: http: // localhost/phpmyadmin
10. Install the redis service and redis Extension
Official sources: Install directly:
sudo apt-get install redis-server
During this period, some required toolkit will also be installed. After the installation is complete, it is automatically started and runs in the background by default. The configuration file is 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
Access http: // localhost/info. php and confirm the redis extension:
Test:
Enter redis-on the terminal and press two tabs to see the commands and tools for redis:
mingc@mingc-GE60-2PL:/etc/redis$ redis-redis-benchmark redis-check-rdb redis-server redis-check-aof redis-cli
Redis-cli is the client interface for accessing redis-server. you can log on to the redis server by executing redis-cli:
mingc@mingc-GE60-2PL:~/Downloads/mysql-fae9884$ redis-cli 127.0.0.1:6379>
For more Command Options of redis-cli, use redis-cli -- help to view them.
Write another php script to test vim/var/www/html/test_redis.php.
The content is as follows:
<?php$redis = new Redis();$redis->connect('127.0.0.1', 6379);echo "Connection to server sucessfully";echo "Server is running: " . $redis->ping();
11. Install mysql extension
As shown in the http: // localhost/info. php above, there is no mysql extension. Although mysql extensions are discarded in PHP 7, some old projects still need them. Install the mysql extension.
Select compile and install here (php-mysql extension installed through apt. If php7.x is used, pdo_mysql extension is installed)
(1) Search for mysql directly from the PECL official site, find the MySQL extension page, click [Browse Source] on the page, select the latest commit, and download the tar.gz package. The downloaded package name isMysql-fae9884.tar.gz.
(2) Compilation and installation:
tar -xf mysql-fae9884.tar.gzcd mysql-fae9884phpize./configure --with-php-config=/usr/bin/php-configsudo make && sudo make install
Php7.1-dev is also installed when php7.1 is installed. phpize and php-config are available here. -- With-php-config is the location of the php-config script (command), which can be viewed using whereis php-config.
After the compilation and installation are successful, a prompt is displayed and the path of the mysql extension module (. so file) is displayed:
Build complete.Don't forget to run 'make test'.Installing shared extensions: /usr/lib/php/20160303/
Then, edit the configuration file/etc/php/7.1apache2/php. ini for apache in php, and add a line at the end:
extension=mysql.so
Restart apche, sudo/etc/init. d/apache2 restart
Access http: // localhost/info. php and check that the mysql extension is available.
Write a php script for testing: vim/etc/www/html/test_mysql.php
The content is as follows:
<?php$mysql = mysql_connect('127.0.0.1', 'root', 'root');if(!$mysql) {die(mysql_error($mysql));}echo 'Ok' . "\r\n";
12. error message about enabling php and apache
Php errors are not displayed by default, which is enabled below.
(1) modify the php configuration file and open php. ini under/etc/php/7.1/apache2.
(2) Search display_errors = Off and change it to On
(3) Search for error_reporting = E_ALL &~ E_NOTICE: change it to E_ALL | E_STRICT (shorter search for unfound images: "error_reporting = ").
(4) modify the apache configuration file and open apache. conf under/etc/apache2.
(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 VM
The apache configuration is used to create a VM. For more information about the apache configuration directory, see:
/Etc/apache2 ── apache2.conf # main configuration file. Some other configuration files are included in the ── conf-available # all available configuration files (in *. almost all conf files are commented out by default.) ── conf-enabled # which configuration files are enabled in the available configuration files, generally, it is a symbolic link pointing to each * in the conf-available Directory above *. conf file ├ ── envvars # environment variable magic ── magic ├ ── mod-available # all available modules ── mod-enabled # which modules are enabled ├ ports. conf # Define Port listening ── sites-available # focus: all available sites ── sites-enabled # which sites are enabled
The steps are simple.Sites-availableThe directory defines the site configuration file, and thenSites-enabled.
(1) Create Configuration
cd /etc/apache2/sites-available/sudo cp 000-default.conf my.site.confvim my.site.conf
Modify the statement as follows (note that there will be a syntax error if you do not place comments and command lines on one line ):
<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. # ServerName my. site # domain name alias. Multiple Domain names can be set and separated by spaces. siteServerAdmin webmaster @ localhostDocumentRoot/var/www/my. site <Directory "/var/www/my. site/"> # enable the symbolic link Options FollowSymLinks DirectoryIndex index. php index.html index.htm # note that this configuration will affect the local directory. enabling AllowOverride All Order deny for htaccess, 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 particle # modules, e.g. # LogLevel info ssl: warnErrorLog $ {APACHE_LOG_DIR}/error. logCustomLog $ {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 participant 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
This is simplified:
<VirtualHost *:80>ServerName my.siteServerAlias my.siteServerAdmin webmaster@localhostDocumentRoot /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/"</Directory>ErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>
(2) Symbolic Link
cd /etc/apache2/sudo ln -s ./sites-available/my.site.conf ./sites-enabled/my.site.conf
(3) Check the syntax
apachectl configtest
(4) Add hosts resolution
Vim/etc/hosts, add a row:
127.0.0.1 my.site
(4) Restart apache
sudo /etc/init.d/apache2 restart
Then, create the Directory and test file according to the configured site directory/etc/www/my. site:
sudo makedir -p /etc/www/my.sitecd /etc/www/my.site/
sudo echo "
ACCESS my. site through a browser,
OK, complete ~~
Reference link:
Related links:
- PHP and extended PPA Source: https://launchpad.net /~ Ondrej/+ archive/ubuntu/php/+ index? Batch = 75 & memo = 75 & start = 75