LAMP environment installation within Ubuntu 14.04

This blog is to tell how to install LAMP environment within Ubuntu 14.04. 

1. Install Mysql Server / Mysql Client.

  1)Login your own server using any user you want.

  2)Type in below command:

sudo apt -get install mysql-server mysql-client

  3)During installation, will let you confirm the default password for mysql root user, will show like below screen shot.

    

    Give them whatever it need, it's fine. Remeber your password, it's important!

   4) After some time waiting for it's own process, try login use the below command:

mysql -uroot -p

   Type in the password that you gave minutes ago and if it goes like this:

    

    Congratulations! Your Mysql server is successfully installed!

    Here I met a little problem, cannot connect mysql server use navicat. Fix like below, file location is /etc/mysql/my.cnf

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address       = 127.0.0.1 bind
-address = 0.0.0.0

2.Insatall PHP

  1)Configure a PPA for co-installable PHP 5.6+7.0

    Type in follow command:

sudo apt-get install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

    OR

 sudo add-apt-repository ppa:ondrej/php

    Form my own experience, I use the first way, and the sample output is like below:

    

    

  2) Update the package index

    To resynchronize the package index files from their sources, enter:

sudo apt-get update

    Waiting until it's all done and type in below command for checking:

apt-cache search php7
Sample result: php7.
0-odbc - ODBC module for PHP php7.0-pgsql - PostgreSQL module for PHP php7.0-pspell - pspell module for PHP php7.0-recode - recode module for PHP php7.0-snmp - SNMP module for PHP php7.0-tidy - tidy module for PHP php7.0-xmlrpc - XMLRPC-EPI module for PHP php7.0-xsl - XSL module for PHP (dummy) php7.0 - server-side, HTML-embedded scripting language (metapackage) php7.0-json - JSON module for PHP php-all-dev - package depending on all supported PHP development packages php7.0-sybase - Sybase module for PHP php7.0-sqlite3 - SQLite3 module for PHP php7.0-mysql - MySQL module for PHP php7.0-opcache - Zend OpCache module for PHP php-apcu - APC User Cache for PHP php-xdebug - Xdebug Module for PHP php-imagick - Provides a wrapper to the ImageMagick library php-ssh2 - Bindings for the libssh2 library php-redis - PHP extension for interfacing with Redis php-memcached - memcached extension module for PHP, uses libmemcached php-apcu-bc - APCu Backwards Compatibility Module php-amqp - AMQP extension for PHP php7.0-bz2 - bzip2 module for PHP php-rrd - PHP bindings to rrd tool system php-uuid - PHP UUID extension php-memcache - memcache extension module for PHP php-gmagick - Provides a wrapper to the GraphicsMagick library php-smbclient - PHP wrapper for libsmbclient php-zmq - ZeroMQ messaging bindings for PHP php-igbinary - igbinary PHP serializer php-msgpack - PHP extension for interfacing with MessagePack php-geoip - GeoIP module for PHP php7.0-bcmath - Bcmath module for PHP php7.0-mbstring - MBSTRING module for PHP php7.0-soap - SOAP module for PHP php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.0-zip - Zip module for PHP php-tideways - Tideways PHP Profiler Extension php-yac - YAC (Yet Another Cache) for PHP php-mailparse - Email message manipulation for PHP php-libsodium - PHP wrapper for the Sodium cryptographic library php-oauth - OAuth 1.0 consumer and provider extension php-propro - propro module for PHP php-raphf - raphf module for PHP php-solr - PHP extension for communicating with Apache Solr server php-stomp - Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP php-gearman - PHP wrapper to libgearman php7.0-dba - DBA module for PHP libapache2-mod-php7.1 - server-side, HTML-embedded scripting language (Apache 2 module) libphp7.1-embed - HTML-embedded scripting language (Embedded SAPI library) php7.1-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.1-cli - command-line interpreter for the PHP scripting language php7.1-dev - Files for PHP7.1 module development php7.1-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.1-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary) php7.1-bcmath - Bcmath module for PHP php7.1-bz2 - bzip2 module for PHP php7.1-common - documentation, examples and common module for PHP php7.1-curl - CURL module for PHP php7.1-dba - DBA module for PHP php7.1-enchant - Enchant module for PHP php7.1-gd - GD module for PHP php7.1-gmp - GMP module for PHP php7.1-imap - IMAP module for PHP php7.1-interbase - Interbase module for PHP php7.1-intl - Internationalisation module for PHP php7.1-json - JSON module for PHP php7.1-ldap - LDAP module for PHP php7.1-mbstring - MBSTRING module for PHP php7.1-mcrypt - libmcrypt module for PHP php7.1-mysql - MySQL module for PHP php7.1-odbc - ODBC module for PHP php7.1-pgsql - PostgreSQL module for PHP php7.1-pspell - pspell module for PHP php7.1-readline - readline module for PHP php7.1-recode - recode module for PHP php7.1-snmp - SNMP module for PHP php7.1-soap - SOAP module for PHP php7.1-sqlite3 - SQLite3 module for PHP php7.1-sybase - Sybase module for PHP php7.1-tidy - tidy module for PHP php7.1-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.1-xmlrpc - XMLRPC-EPI module for PHP php7.1-zip - Zip module for PHP php7.1-opcache - Zend OpCache module for PHP php7.1 - server-side, HTML-embedded scripting language (metapackage) php7.1-xsl - XSL module for PHP (dummy)

  3) Install PHP7

sudo apt-get install php7.0

   4)Checking if php has mysql module

sudo cat /etc/php/7.0/mods-available/mysqlnd.ini

     This will give you results like below screenshot which means your extension is successfully installed:

      

     If not, type:

sudo apt-get install php7.0-mysql

     And then check.

3. Install Apache2

  1) Install.

    Update software source.

sudo apt-get update

    Install Apache

apt-get install apache2

    Check if Apache is successfully installed

apache2 -v

    If it shows like below, then access your own server by typing your IP addressand if it is able to access, then it works!

      

  2) Check the php extension.

    Create a new info.php in the directory : /var/www/html

<?php
$link = mysqli_connect("127.0.0.1", "your_username", "your_password", "mysql");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);

phpinfo();
?>

    And then access your IP/info.php using browser, If it shows like below, your installation is success!!

      

Some key points when set up the environment:

  1) Make sure you have only one php version for apache, since if php7.0 and php5 are both in apache mods, it will conflict and unable to start apache.

  2) Modify /etc/apache2/apache2.conf, Add one line under the #Global configuration, and then restart apache.

# Global configuration
#
ServerName 127.0.0.1

 

原文地址:https://www.cnblogs.com/mumu95/p/5807142.html