
SETUP A LAMP SERVER FROM SCRATCH
Many times, you will need to setup a new work environment such as staging or live, or you may need to setup your local development environment. To do so, the following steps would be pretty helpful for you.
If you want to remove a previous or useless installation
1 sudo apt-get remove --auto-remove php7.0 php5.6 php7.1 php5.5 php5
Install PHP 5.6 and 7.0
123456 sudo add-apt-repository ppa:ondrej/phpsudo apt-get updatesudo apt-get install php5.6sudo apt-get install php7.0
Install other useful PHP dependencies
For PHP 5.6
1 sudo apt-get install php5.6-mysql php5.6-gettext php5.6-mbstring php5.6-gd php5.6-mcrypt php5.6-curl php5.6-intl php5.6-xsl php5.6-mbstring php5.6-zip php-xdebug php5.6-gd php5.6-mcrypt php5.6-curl php5.6-intl php5.6-xsl php5.6-mbstring php5.6-zip php5.6-bcmath
For PHP 7.0
1 sudo apt-get install php7.0-mysql php7.0-gettext php7.0-mbstring php7.0-gd php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php-xdebug php7.0-gd php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath
Install Apache2
12345 sudo add-apt-repository ppa:ondrej/apache2sudo apt-get updatesudo apt-get install apache2
Once you have installed apache, you should install the following dependencies to link it with PHP.
For PHP 5.6
12345 sudo apt-get install libapache2-mod-php5.6sudo a2enmod php5.6sudo service apache2 restart
For PHP 7.0
12345 sudo apt-get install libapache2-mod-php7.0sudo a2enmod php7.0sudo service apache2 restart
Install MySQL 5.7
12345 sudo add-apt-repository -y ppa:ondrej/mysql-5.7sudo apt-get install mysql-client-core-5.7sudo apt-get install mysql-server-5.7
Note: If you have a previous mysql installation, you will need to remove it before starting the installation of mysql 5.6, otherwise, you will have conflicts. To remove all previous mysql installation, do the following:
123456789 sudo apt-get remove --purge mysqlsudo apt-get remove --purge mysql*sudo apt-get autoremovesudo apt-get autocleansudo rm -rf /var/lib/mysql
Moreover, you can take a look at previous installed packages, as follows:
1 dpkg -l|grep mysql
Both MySQL database core client and MySQL Server packages, needs to be the same version.
MySQL Client 5.5 and MySQL Server 5.5 are the current “best” versions of these packages in Ubuntu 14.04 as determined by the package maintainers, however, if you need to work with Magento 2, its mandatory to install at least MySQL 5.6
Once you have installed Apache, MySQL , and PHP. You will be able to create many virtual hosts as you want for your sites.
To create a new virtual host, you need to perform the following steps:
Make sure that the followings mods are available:
1 2 3 |
sudo a2enmod rewrite sudo a2enmod headers |
Edit your apache configuration in order to allow override and htaccess support, as follows:
1 2 3 4 5 6 7 8 9 10 11 12 |
# Open your apache2.conf file $ sudo nano /etc/apache2/apache2.conf # Search the line which starts with <Directory \> AllowOverride None # And replace it with <Directory \> AllowOverride All # Save the file and restart apache |
Under /etc/apache2/sites-available create a file called: local.<site_name>.com.conf with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName local.<site_name>.com DocumentRoot /path/to/your/<site_name>/www ErrorLog /path/to/your/<site_name>/log/error.log CustomLog /path/to/your/<site_name>/log/access.log combined <Directory /path/to/your/<site_name>/www> Order allow,deny Allow from all Require all granted AllowOverride All </Directory> </VirtualHost> |
Then, you will need to enable this virtual host:
1 2 3 4 5 6 7 |
# Copying the conf file to sites-enabled cd /etc/apache2/ sudo cp sites-available/local.<site_name>.com.conf sites-enabled/. # Or enabling the site with apache commands sudo a2ensite local.<site_name>.com.conf sudo service apache2 reload |
The next step, is to add the entry to your hosts file, located at /etc/hosts
1 2 3 4 5 6 |
# You can do so, editing the file with a file editor as gedit / nano / vi sudo gedit /etc/hosts 127.0.0.1 local.<site_name>.com # add this line at the bottom # Or you can do it straight from CLI sudo echo "127.0.0.1 local.<site_name>.dev" >> /etc/hosts |
Restart apache
1 |
sudo service apache2 restart |
Make a try on your browser and you should see your site (or the content of the index.php of your directory folder).
Notes:
- If you watch an error 500, take a look at your error.log file.
- In the case you are working on Magento, and that’s your first running, it could be usual to see the following error:PHP Fatal error: Call to undefined function simplexml_load_string()To fix it, proceed with the following steps:
123456789101112sudo apt-get install php<version>-xml# Add on the top of your index.php the following:phpinfo();die();# Get the path of your php.ini file and edit it ( sudo nano /path/of/your/php.ini ).# Find the following line, and uncomment it:extension=php_xmlrpc.dll# Let's restart apache:sudo service apache2 restart
- Try again, and you should see your site properly.