There are a lots of complications when trying to install AMP stack on Arch Linux. I tried many things and this is what worked for me. Hope it will help you too.
Apache
To install Apache web server you can use pacman as following.
$ sudo pacman -S apache
Then it will be installed and now you have to configure the server. All the configurations are stored in /etc/httpd/conf/httpd.conf
file and use your favorite editor to edit it. (in my case, it’s nano
)
$ sudo nano /etc/httpd/conf/httpd.conf
Now we will peek into few important settings.
Port
Listen 80
This is the port where HTTP daemon runs. You can change it if you want, but 80 is the default HTTP port.
Comment the “unique_id_module”
You can use CTRL+w to find it in nano
. Then that line will be as following.
#LoadModule unique_id_module modules/mod_unique_id.so
ServerAdmin
This is optional, you can change the server admin email address, so it will be displayed on server error messages.
ServerAdmin gnomez.grave@gmail.com
Restart HTTPD
You can use systemctl to deal with httpd. Remember to restart the httpd whenever you’ve done any change to any apache related configuration.
$ sudo systemctl restart httpd
If it gives you a warning like
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
you should edit
/etc/hosts
and insert localhost
as an entry.
For that, use $ sudo nano /etc/hosts
and add localhost
to the entry with 127.0.0.1
. Then it will look like this.
127.0.0.1 localhost.localdomain localhost arch
Now your Apache server is ready to go. Your public_html folder is located in /srv/http
by default.
Now lets test the server. Create index.html file inside and type a simple HTML code. (For now, you need admin privileges to write to /srv/http. We will see how to fix that later on.)
$ sudo nano /srv/http/index.html <html> <head><title>Apache Home</title></head> <body><h1>Apache Server is working..!!</h1></body> </html>
Then open your web browser and type localhost
and press enter. Your browser should show “Apache Server is working..!!”.
Change the default Document Root
The default doc root is /srv/http. If you want to change it to something like /home/praneeth/www
, here is the way.
Open httpd.conf file and edit the following.
DocumentRoot "/home/praneeth/WWW"
and
<Directory "/home/praneeth/WWW">
to the same directory you specified above. But now if you tried to access localhost after restarting httpd, you may get an "Access forbidden Error 403 localhost" error
. That’s because http
user don’t have permission to read the directory you specified.
There are few ways to fix this, but I’m mentioning the way worked for me.
To fix this, http user MUST be given the permission to your specified folder. So you simply can add http user to the user group, where the owner of your home directory belongs. (in my case it’s users
)
$ sudo gpasswd -a http users
But now, every user in the above user group have the access to that folder. So you can do something like this.
$ sudo chmod g+xr-w /home/praneeth $ sudo chmod -R g+xr-w /home/praneeth/www
Baaamm..!! Now you are ready to go. Restart the httpd and refresh your web browser.
PHP
To install php and other needed libraries, you can use following command.
$ sudo pacman -S php php-apache php-gd php-mcrypt
It will install PHP, but still you have to enable it in httpd.conf. Open httpd.conf and add these lines to the bottom of it.
# Use for PHP 5.x: LoadModule php5_module modules/libphp5.so AddHandler php5-script php Include conf/extra/php5_module.conf
(Don’t forget to restart httpd)
Now you are done with PHP. Now test it by creating a .php file (ex: info.php) in your doc root and type these lines in it.
<?php phpinfo(); ?>
Save it and type localhost/info.php and you should get the PHP Info page.
MySQL
You can install MySQL by following command. (Now MySQL distribution for Arch Linux is known as MariaDB)
$ sudo pacman -S mysql
Then it will install MySQL and you can run the MySQL server by using systemctl.
$ sudo systemctl start mysqld
Then you can configure the MySQL server by following command.
$ sudo mysql_secure_installation
Then you can change the configurations. (It’s better if you enter a password for the MySQL server.)
Now you have to enable MySQL to communicate with PHP. For that you have to edit php.ini and enable mysql.
$ sudo nano /etc/php/php.ini
Remove the semi-colon (;) before the expected extensions to be enabled.
extension=mysqli.so extension=mysql.so
Now you are ready to go with Apache-MySQL-PHP.
PHPMyAdmin
PHPMyAdmin is a GUI to manage you MySQL databases. You can install it by as following.
$ sudo pacman -S phpmyadmin
You have to install php-mcrypt if you don’t have it.
Now you need following command to get a sample config file for PHPMyAdmin.
$ sudo cp /etc/webapps/phpmyadmin/apache.example.conf /etc/httpd/conf/extra/httpd-phpmyadmin.conf
And add these lines to httpd.conf
# phpMyAdmin configuration Include conf/extra/httpd-phpmyadmin.conf
If you want to allow access from any host, edit /etc/webapps/phpmyadmin/.htaccess and change
deny from all
to
allow from all
And make sure /etc/httpd/conf/extra/httpd-phpmyadmin.conf has following information.
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin" <Directory "/usr/share/webapps/phpMyAdmin"> AllowOverride All Options FollowSymlinks Order allow,deny Allow from all php_admin_value open_basedir "/srv/:/tmp/:/usr/share/webapps/:/etc/webapps:/usr/share/pear/" </Directory>
Go to your web browser and enter localhost/phpmyadmin
and you should get it working.
Reblogged this on Sutoprise Avenue, A SutoCom Source.
[…] Solved problems in ugrading to Apache 2.4.[…]